CONTENTS | INDEX | PREV | NEXT
fgetc
getc
NAME
fgetc - get a single character from a file pointer
getc - get a single character from a file pointer (MACRO)
SYNOPSIS
#include <stdio.h>
int c = fgetc(fp);
int c = getc(fp); (MACRO)
FILE *fp;
FUNCTION
[f]getc() reads a single character from a file pointer. The value
returned is actually an int because EOF (-1) must be differentiated
from a 255.
[f]getc() returns an integer 0-255 or EOF (-1) if an end of file
occurs.
NOTE
refer to the file_pointer manual page for general information
EXAMPLE
/*
* copy stdin to stdout using getc/putc. Normally one uses
* fread/fwrite, but I'll save that for the fread manual page.
*
* note that I output the initial message to stderr so it does
* not get stuck into stdout in case the user has redirected
* stdout.
*/
#include <stdio.h>
main()
{
int c;
fputs("Type a couple of lines, then ^ (EOF)n", stderr);
while ((c = getc(stdin)) != EOF) {
putc(c, stdout);
}
return(0);
}
INPUTS
FILE *fp; file pointer
RESULTS
int c; character 0 to 255, or EOF (-1).
SEE ALSO
putc, fputc, fread, fwrite